//
//  GifLoaders.m
//  PersonalTool
//
//  Created by Samuel on 2/10/15.
//  Copyright (c) 2015 Samuel. All rights reserved.
//

#import "GifLoaders.h"
#import <ImageIO/ImageIO.h>
#import "SCGIFImageView.h"

@implementation GifLoaders
+ (NSMutableArray*)getGifData:(NSData*)datas;
{
    CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)datas, NULL);
    size_t count = CGImageSourceGetCount(source);
    
    NSMutableArray* tmpArray = [NSMutableArray array];
    
    for (size_t i = 0; i < count; i++) {
        //        UIImage* gifImage = [[[SCGIFImageFrame alloc] init] autorelease];
        
        CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
        UIImage *image2 = [UIImage imageWithCGImage:image scale:.3 orientation:UIImageOrientationUp];
        
        //        NSDictionary* frameProperties = [(NSDictionary*)CGImageSourceCopyPropertiesAtIndex(source, i, NULL) autorelease];
        //        gifImage.duration = [[[frameProperties objectForKey:(NSString*)kCGImagePropertyGIFDictionary] objectForKey:(NSString*)kCGImagePropertyGIFDelayTime] doubleValue];
        //        gifImage.duration = MAX(gifImage.duration, 0.01);
        
        [tmpArray addObject:image2];
        
        CGImageRelease(image);
    }
    CFRelease(source);
    
    return tmpArray;
}
@end
